﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ruanmou.Framework.CommonHelper
{
    /// <summary>
    /// 静态构造函数的完成路径的创建  不需要每次都判断路径
    /// </summary>
    public  class LogHelper
    {

        static LogHelper()
        {
            string rootPath = StaticConstant.LogRootPath;

            if (!Directory.Exists(rootPath))
            {
                Directory.CreateDirectory(rootPath);
            }
        }


        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="message"></param>
        public static void WriteLog(string message)
        {
            string rootPath = StaticConstant.LogRootPath;

            string fileName =$"{DateTime.Now.ToString("yyyy-MM-dd")}.txt";
            if (!Directory.Exists(rootPath))
            {
                Directory.CreateDirectory(rootPath);
                WriteLog(message);//小show一下
            }
            var fullName = Path.Combine(rootPath, fileName);
            using (StreamWriter sw = File.AppendText(fullName))
            {
                sw.WriteLine($"{DateTime.Now}  :  {message}");
            }
        }

    }
}
